package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.Command;
import com.wtwd.campus.entity.DeviceSOSList;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.entity.MqSetAllSosCall;
import com.wtwd.campus.utils.UnicodeUtil;

import java.util.List;
import java.util.Map;

/**
 * @author mjy
 * @date 2021/07/20
 * @description
 */
public class SetAllSoSSender implements Sender {
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        MqSetAllSosCall mqSetAllSosCall = (MqSetAllSosCall) mqMessage.getObject();
        String imei = mqSetAllSosCall.getImei();
        String commandNumber = mqSetAllSosCall.getCommandNumber();
        List<DeviceSOSList> sosCallList = mqSetAllSosCall.getSosCallList();
        String cmd = mqMessage.getType();
        String allSosContent = "";
        for (DeviceSOSList deviceSOSList : sosCallList) {
            String name = deviceSOSList.getSosName();
            String phone = deviceSOSList.getSosPhone();
            String sequence = String.valueOf(deviceSOSList.getSequence());
            String parseName = UnicodeUtil.gbEncoding(name);
            allSosContent=allSosContent.concat(",").concat(sequence).concat(",").concat(parseName).concat(",").concat(phone);
        }
        String content="*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(imei).concat(",").concat(cmd).concat(",")
                .concat(commandNumber).concat(allSosContent).concat("#");
        Command command = new Command();
        command.setImei(imei);
        command.setContent(content);
        command.setCmd(cmd);
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setCommandNumber(commandNumber);
        return command;
    }
}
